SynchronizedCollection
Represents a thread-safe collection that provides synchronization for its operations.
继承自: BaseCollection<T, T>
实现: ISynchronizedCollection<T>, ISynchronizedCollection, ISynchronizable, ICollection<T>, IEnumerable<T>, IEnumerable
构造函数
protected SynchronizedCollection(TCollection innerCollection)
synchronizedCollection = SynchronizedCollection(innerCollection)
Represents a thread-safe collection that provides synchronization for its operations.
属性
public override int Count { get; }
value = synchronizedCollection.Count
Gets the number of elements contained in the collection.
public override TItem Item { get; set; }
value = synchronizedCollection.Item
synchronizedCollection.Item = value
Gets or sets the element at the specified index.
- index
- The zero-based index of the element to get or set.
返回值: The element at the specified index.
public Lock SyncRoot { get; }
value = synchronizedCollection.SyncRoot
Gets the synchronization root object used to synchronize access to the collection.
方法
public override void Add(TItem item)
synchronizedCollection.Add(item)
Adds an item to the collection.
- item
- The item to add to the collection.
public override void Clear()
synchronizedCollection.Clear()
Removes all items from the collection.
public override bool Contains(TItem item)
result = synchronizedCollection.Contains(item)
Determines whether the collection contains a specific item.
- item
- The item to locate in the collection.
返回值: true if the item is found in the collection; otherwise, false.
public Scope EnterScope()
result = synchronizedCollection.EnterScope()
Enters a synchronized scope for thread-safe operations on the collection.
返回值: A Scope that represents the synchronized scope.
public override IEnumerator<TItem> GetEnumerator()
result = synchronizedCollection.GetEnumerator()
Returns an enumerator that iterates through the collection.
返回值: An enumerator that can be used to iterate through the collection.
public override int IndexOf(TItem item)
result = synchronizedCollection.IndexOf(item)
Determines the index of a specific item in the collection.
- item
- The item to locate in the collection.
返回值: The index of the item if found in the collection; otherwise, -1.
public override void Insert(int index, TItem item)
synchronizedCollection.Insert(index, item)
Inserts an item into the collection at the specified index.
- index
- The zero-based index at which the item should be inserted.
- item
- The item to insert into the collection.
protected abstract int OnIndexOf(TItem item)
result = synchronizedCollection.OnIndexOf(item)
When overridden in a derived class, determines the index of a specific item in the collection.
- item
- The item to locate in the collection.
返回值: The index of the item if found in the collection; otherwise, -1.
public override bool Remove(TItem item)
result = synchronizedCollection.Remove(item)
Removes the first occurrence of a specific item from the collection.
- item
- The item to remove from the collection.
返回值: true if the item was successfully removed; otherwise, false.
public override void RemoveAt(int index)
synchronizedCollection.RemoveAt(index)
Removes the item at the specified index.
- index
- The zero-based index of the item to remove.